package com.scau.database.service.user;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.scau.data.entity.UserDO;
import com.scau.database.common.service.ImportMapperService;
import com.scau.database.entity.user.UserLoginVO;
import com.scau.database.exception.APIException;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName: LoginService
 * @Description: TODO
 * @Author: sunslikes
 * @Date: 2020/6/29 16:53
 * @Version: 1.0
 */
@Service
public class LoginService {
    @Autowired
    ImportMapperService importMapperService;

    public UserLoginVO login(UserLoginVO loginVO) {
        UserDO userDOCondition = new UserDO();
        BeanUtils.copyProperties(loginVO, userDOCondition);
        UserDO userDO = importMapperService.userMapper.selectOne(new QueryWrapper<>(userDOCondition));
        System.out.println(userDO);
        if (userDO == null) {
            throw new APIException("登录错误！");
        }
        loginVO.setServiceId(userDO.getServiceId());
        loginVO.setStoreId(userDO.getStoreId());
        loginVO.setWarehouseId(userDO.getWarehouseId());
        // 把密码变成空。
        loginVO.setPassword(null);
        return loginVO;
    }

}
